package com.ruoyi.email.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.email.domain.TmdEmailWrite;
import com.ruoyi.email.mapper.TmdEmailPostMapper;
import com.ruoyi.email.service.ITmdEmailPostService;
import com.ruoyi.email.vo.TmdEmailWriteAndSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TmdEmailPostServiceimpl implements ITmdEmailPostService {
    @Autowired
    private TmdEmailPostMapper tmdEmailPostMapper;
    @Override
    public List<TmdEmailWriteAndSysUser> selectTmdEmailWriteList(TmdEmailWrite tmdEmailWrite) {
        SysUser sysUser = ShiroUtils.getSysUser();
        String userName = sysUser.getUserName();
        List<TmdEmailWriteAndSysUser> list=new ArrayList<>();
        List<TmdEmailWriteAndSysUser> tmdEmailWriteAndSysUsers = tmdEmailPostMapper.selectTmdEmailWriteList(tmdEmailWrite);
        for (TmdEmailWriteAndSysUser eve:tmdEmailWriteAndSysUsers) {
            if (eve.getPersonName().equals(userName)){
                list.add(eve);
            }
        }
        return list;
    }

    @Override
    public TmdEmailWriteAndSysUser selectTmdEmailWriteById(Integer id) {
        return tmdEmailPostMapper.selectTmdEmailWriteById(id);
    }

    @Override
    public int deleteTmdEmailWriteByIds(String ids) {
        return tmdEmailPostMapper.deleteTmdEmailWriteByIds(Convert.toStrArray(ids));
    }
}
